/**
/**
 * JAVACC DEMO 1.0
 */

package freemarker.core;

import java.io.IOException;
import java.util.Map;

import freemarker.cache.TemplateCache;
import freemarker.core.Environment;
import freemarker.template.TemplateDirectiveBody;
import freemarker.template.TemplateException;
import freemarker.template.TemplateModel;
import freemarker.template.utility.StringUtil;

/**
 * description:  
 * @author Hou Dayu 创建时间：2016-7-28
 */

public class ExtendsDirective extends AbstractDirective {
	public static final String DIRECTIVE_NAME = "extends";

	public void execute(Environment env, Map params, TemplateModel[] loopVars, TemplateDirectiveBody body)
			throws TemplateException, IOException {
		String name = getRequiredParam(params, "path");
		String encoding = getParam(params, "encoding", null);
		String parse = getParam(params, "parse", "true");
		String includeTemplateName = TemplateCache.getFullTemplatePath(env, getTemplatePath(env), name);

		EnvironmentWrapper environmentWrapper = new EnvironmentWrapper(env);
		environmentWrapper.include(env.getTemplateForInclusion(includeTemplateName, encoding,
				StringUtil.getYesNo(parse)));
	}

	public String getDirectiveName() {
		return "extends";
	}
}
